package com.serie402.web.servlet;

import com.kiss.fw.servlets.AbstractStartupServlet;
import com.kiss.fw.utils.Util;
import com.serie402.common.bo.News;
import com.serie402.web.jsf.mb.MenuManagedBean;

/**
 * Servlet implementation class StartupServlet
 */
public class StartupServlet extends AbstractStartupServlet {
	private static final long serialVersionUID = 1L;
//	private static final Logger logger = Logger.getLogger(StartupServlet.class);
	
	private void loadTopNews() throws Exception {
//		NewsDAODTO dto = new NewsDAODTO();
//		dto.setCategory(Constants.NEWS_CATEGORY_TOP_NEWS_FOR_EACH_CATEGORY);
//		
//		NewsPageDTO returnDTO = (NewsPageDTO) NewsDAO.getInstance().read(dto);
//		News[] topNews = returnDTO.getTopNews();
//		
//		if (topNews != null && topNews.length > 0) {
//			News tempNews = null;
//			
//			for(int i = 0; i < topNews.length; i++) {
//				if(Constants.NEWS_CATEGORY_SPORTS.equals(topNews[i].getCategory())) {
//					MenuManagedBean.setSportsBoxedContent(topNews[i]);
//				}
//				else {
//					if(tempNews == null) {
//						tempNews = topNews[i];
//					}
//					else if (tempNews.getImportance() < topNews[i].getImportance()) {
//						tempNews = topNews[i];
//					}
//				}
//			}
//			
//			// we only want hot and breaking news to be displayed
//			if(tempNews != null && (tempNews.getImportance() == Constants.NEWS_IMPORTANCE_BREAKING || tempNews.getImportance() == Constants.NEWS_IMPORTANCE_HOT)) {
//				MenuManagedBean.setNewsBoxedContent(tempNews);
//			}
//		}
		News n = new News();
		n.setTitle("This is the Title of the News");
		n.setNewsId(1234);
		n.setImportance(5);
		
		MenuManagedBean.setNewsBoxedContent(n);
		MenuManagedBean.setSportsBoxedContent(n);
	}
	
	private void loadGallery() throws Exception {
	}
	
	private void loadEvents() throws Exception {
	}
	
	@Override
	protected void startup() throws Exception {
		loadTopNews();
		loadGallery();
		loadEvents();
		Util.sendEmailNotification(StartupServlet.class, "startup", null, null);
	}
	
	@Override
	protected void cleanUp() throws Exception {
		Util.sendEmailNotification(StartupServlet.class, "cleanUp", null, null);
	}
}